//
//  ConfigSearchViewCell.swift
//  SunxianhuaTestApp
//
//  Created by abc on 2021/10/12.
//

import Foundation
import UIKit
class ConfigSearchViewCell:  UICollectionViewCell{
    
    /// 定义回调
    typealias CallbackValue=()->Void
    /// 声明闭包
    var chooesCallbackValue:CallbackValue?
    
    var titleLabel :UILabel = UILabel()
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.creatView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func creatView(){
        
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.left.equalTo(10.0)
            make.bottom.right.equalTo(-10.0)
        }
        titleLabel.textAlignment = .center
        titleLabel.text = "标签"
        titleLabel.font = UIFont.systemFont(ofSize: 14.0)
        
        titleLabel.backgroundColor = UIColor.set_Color(200, green: 200, blue: 200, alpha: 0.5)
        UIView.setRadius(titleLabel, radius: 5.0)
        
        
        let tap = UILongPressGestureRecognizer.init(target: self, action: #selector(longAction))
        self.titleLabel.isUserInteractionEnabled = true
        self.titleLabel.addGestureRecognizer(tap)
    }
    
    
    @objc private func longAction(){
        self.chooesCallbackValue?()
    }
    
    func reloadCell(cellModel :SearchKeyModel ,isSelected :Bool,longBlock :(()->Void)?){
        self.titleLabel.text = cellModel.key
        
        self.titleLabel.backgroundColor = isSelected ? UIColor.red : UIColor.set_Color(200, green: 200, blue: 200, alpha: 0.5)
        self.titleLabel.textColor = isSelected ? UIColor.white : UIColor.black
        
        self.chooesCallbackValue = longBlock
    
    }
    
    
}
